import { request } from '@/utils/request'

// 用户服务API基础路径
const USER_API_BASE = '/api/zenithMind/user'
const VERIFICATION_API_BASE = '/api/zenithMind/verification'

export const userApi = {
  /**
   * 用户登录 (需要验证码)
   */
  login(data) {
    return request.post(`${USER_API_BASE}/loginUser`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 简单用户登录 (测试用，不需要验证码)
   */
  simpleLogin(data) {
    return request.post(`${USER_API_BASE}/simpleLogin`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 管理员登录
   */
  adminLogin(data) {
    return request.post(`${USER_API_BASE}/loginAdmin`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 用户注册
   */
  register(data) {
    return request.post(`${USER_API_BASE}/registerUser`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 用户登出
   */
  logout() {
    return request.get(`${USER_API_BASE}/logoutUser`)
  },

  /**
   * 获取当前用户信息
   */
  getUserInfo() {
    return request.get(`${USER_API_BASE}/getCurrentUser`)
  },

  /**
   * 更新用户信息
   */
  updateUserInfo(data) {
    return request.put(`${USER_API_BASE}/updateLoginUser`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 修改密码
   */
  updatePassword(data) {
    return request.put(`${USER_API_BASE}/password`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 上传头像
   */
  uploadAvatar(file) {
    return request.upload(`${USER_API_BASE}/avatar`, file, {
      showSuccessMessage: true
    })
  },

  /**
   * 获取用户权限
   */
  getUserPermissions() {
    return request.get(`${USER_API_BASE}/permissions`)
  },

  /**
   * 获取学习统计
   */
  getLearningStats() {
    return request.get(`${USER_API_BASE}/learning-stats`)
  },

  /**
   * 获取成就数据
   */
  getAchievements() {
    return request.get(`${USER_API_BASE}/achievements`)
  },

  /**
   * 更新用户偏好
   */
  updatePreferences(data) {
    return request.put(`${USER_API_BASE}/preferences`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 记录学习时间
   */
  recordStudyTime(data) {
    return request.post(`${USER_API_BASE}/study-time`, data)
  },

  /**
   * 用户签到
   */
  checkIn() {
    return request.post(`${USER_API_BASE}/check-in`, {}, {
      showSuccessMessage: true
    })
  },

  /**
   * 获取签到记录
   */
  getCheckInRecords(params) {
    return request.get(`${USER_API_BASE}/check-in/records`, params)
  },

  /**
   * 绑定邮箱
   */
  bindEmail(data) {
    return request.post(`${USER_API_BASE}/bind-email`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 绑定手机号
   */
  bindPhone(data) {
    return request.post(`${USER_API_BASE}/bind-phone`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 解绑邮箱
   */
  unbindEmail(data) {
    return request.post(`${USER_API_BASE}/unbind-email`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 解绑手机号
   */
  unbindPhone(data) {
    return request.post(`${USER_API_BASE}/unbind-phone`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 获取用户关注列表
   */
  getFollowList(params) {
    return request.get(`${USER_API_BASE}/follow`, params)
  },

  /**
   * 获取用户粉丝列表
   */
  getFansList(params) {
    return request.get(`${USER_API_BASE}/fans`, params)
  },

  /**
   * 关注用户
   */
  followUser(userId) {
    return request.post(`${USER_API_BASE}/follow/${userId}`, {}, {
      showSuccessMessage: true
    })
  },

  /**
   * 取消关注用户
   */
  unfollowUser(userId) {
    return request.delete(`${USER_API_BASE}/follow/${userId}`, {
      showSuccessMessage: true
    })
  },

  /**
   * 获取用户资料
   */
  getUserProfile(userId) {
    return request.get(`${USER_API_BASE}/profile/${userId}`)
  },

  /**
   * 搜索用户
   */
  searchUsers(params) {
    return request.get(`${USER_API_BASE}/search`, params)
  },

  /**
   * 获取推荐用户
   */
  getRecommendedUsers(params) {
    return request.get(`${USER_API_BASE}/recommended`, params)
  },

  /**
   * 获取在线用户
   */
  getOnlineUsers(params) {
    return request.get(`${USER_API_BASE}/online`, params)
  },

  /**
   * 举报用户
   */
  reportUser(data) {
    return request.post(`${USER_API_BASE}/report`, data, {
      showSuccessMessage: true
    })
  },

  /**
   * 拉黑用户
   */
  blockUser(userId) {
    return request.post(`${USER_API_BASE}/block/${userId}`, {}, {
      showSuccessMessage: true
    })
  },

  /**
   * 取消拉黑用户
   */
  unblockUser(userId) {
    return request.delete(`${USER_API_BASE}/block/${userId}`, {
      showSuccessMessage: true
    })
  },

  /**
   * 获取拉黑列表
   */
  getBlockList(params) {
    return request.get(`${USER_API_BASE}/block`, params)
  }
}

// 验证码相关API
export const verificationApi = {
  /**
   * 发送注册验证码到邮箱
   */
  sendRegisterCode(data) {
    return request.get(`${VERIFICATION_API_BASE}/sendRegisterEmailCode`, {
      params: data,
      showSuccessMessage: true
    })
  },

  /**
   * 发送登录验证码
   */
  sendLoginCode(data) {
    return request.get(`${USER_API_BASE}/sendLoginVerificationCode`, {
      params: data,
      showSuccessMessage: true
    })
  },

  /**
   * 验证验证码
   */
  verifyCode(data) {
    return request.post(`${VERIFICATION_API_BASE}/verifyVerificationCode`, data)
  },

  /**
   * 获取图形验证码
   */
  getCaptcha() {
    return request.get(`${VERIFICATION_API_BASE}/captcha`)
  }
}
